package com.ae.shield.common.items.shieldFittings.makers;

import com.ae.shield.common.enchantment.shieldSuffix.SuffixList;
import com.ae.shield.common.items.util.DamageSorter;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraftforge.energy.IEnergyStorage;

import javax.annotation.Nonnull;
import java.util.List;

public class PlasmaShield extends ShieldMakerBase {
    public PlasmaShield() {
        super(new Properties(), new ShieldProperty()
                .recovery(0.15f)
                .cd(32)
                .maxIntensity(24f)
                .close(0.4f)
                .remote(1.6f)
                .magic(0f)
                .other(0f)
                .upperLimit(30f)
                .floorLimit(0f)
                .maxPiles(2)
                .penalty(10f)
                .cost(7));
    }

    @Override
    public void addCtrlInformation(List<ITextComponent> components, ItemStack stack) {
        components.add(new TranslationTextComponent("tooltip.ae.shield.plasma_shield.tip1").mergeStyle(TextFormatting.GRAY));
        components.add(new TranslationTextComponent("tooltip.ae.shield.plasma_shield.tip2").mergeStyle(TextFormatting.GRAY));
        components.add(new TranslationTextComponent("tooltip.ae.shield.plasma_shield.tip3").mergeStyle(TextFormatting.DARK_RED));
        components.add(new TranslationTextComponent("tooltip.ae.shield.plasma_shield.tip4").mergeStyle(TextFormatting.BLUE));
        components.add(new TranslationTextComponent("tooltip.ae.shield.plasma_shield.tip5").mergeStyle(TextFormatting.GOLD));
        components.add(new TranslationTextComponent("tooltip.ae.shield.plasma_shield.tip6").mergeStyle(TextFormatting.BLUE));
        components.add(new TranslationTextComponent("tooltip.ae.shield.plasma_shield.tip7").mergeStyle(TextFormatting.GRAY));
    }

    @Override
    public float onShieldWorked(LivingEntity entity, ItemStack stack, float amount, float residue, DamageSource source, IEnergyStorage energyCap) {
        Entity trueSource = source.getTrueSource();
        int level = EnchantmentHelper.getEnchantmentLevel(SuffixList.LEVEL_UP.get(), stack);

        if (trueSource != null && DamageSorter.sort(source) == DamageSorter.CLOSE) {
            DamageSource damageSource = new DamageSource("shield_maker") {
                @Nonnull
                @Override
                public ITextComponent getDeathMessage(@Nonnull LivingEntity entityLivingBaseIn) {
                    String s = "death.attack.plasma_shield" + (random.nextInt(3) + 1);
                    return new TranslationTextComponent(s, entityLivingBaseIn.getDisplayName(), entity.getDisplayName());
                }
            };

            switch (DamageSorter.sort(source)) {
                case CLOSE:
                    trueSource.attackEntityFrom(damageSource, amount * 0.15f * (level + 1) * (random.nextInt(5) + 1));
                default:
                    trueSource.attackEntityFrom(damageSource, amount * 0.1f * (level + 1));
            }
        } else if (DamageSorter.sort(source) == DamageSorter.SHIELD) {
            return residue;
        }

            return residue;
    }
}
